package com.chinasoft.mall.activity.adapter;

import java.util.List;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.chinasoft.mall.R;
import com.chinasoft.mall.activity.MainActivity;
import com.chinasoft.mall.model.response.ModellistBean;
import com.chinasoft.mall.util.StringUtil;
import com.chinasoft.mall.widget.NetImageView;

public class ModelListAdapter extends BaseAdapter {
	private List<ModellistBean> dds;
	private LayoutInflater inflater;
	private ViewHolder _vh;

	public ModelListAdapter(MainActivity MainActivity, List<ModellistBean> crs) {
		inflater = LayoutInflater.from(MainActivity);
		this.dds = crs;
	}

	public void setData(List<ModellistBean> crs) {
		this.dds = crs;
		this.notifyDataSetChanged();
	}

	@Override
	public int getCount() {
		if (dds == null) {
			return 0;
		} else {
			return dds.size();
		}
	}

	@Override
	public Object getItem(int position) {
		if (dds == null) {
			return null;
		} else {
			return dds.get(position);
		}
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.sy_modellistlv, null);
			_vh = new ViewHolder();
			_vh.modelimg = (NetImageView) convertView
					.findViewById(R.id.modelimg);
			_vh.modeltitle = (TextView) convertView
					.findViewById(R.id.modeltitle);
			_vh.modelcontent = (TextView) convertView
					.findViewById(R.id.modelcontent);
			convertView.setTag(_vh);
		} else {
			_vh = (ViewHolder) convertView.getTag();
		}
		ModellistBean _dd = dds.get(position);
		_vh.modelimg
				.setDownloadurl(StringUtil.modelImageUrl(_dd.getMODEL_ID(),_dd.getTHUM()));
		_vh.modeltitle.setText(_dd.getMODEL_NAME());
		_vh.modelcontent.setText(_dd.getINTRO());

		return convertView;
	}

	class ViewHolder {
		public NetImageView modelimg;
		public TextView modeltitle;
		public TextView modelcontent;
	}
}
